package com.tuantuan.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuantuan.dao.UsersDao;
import com.tuantuan.model.UserOrder;
import com.tuantuan.model.Users;
import com.tuantuan.service.UsersService;
import com.tuantuan.utils.UntilEntity;
@Service("UsersService")
@Transactional
public class UsersServiceImpl implements UsersService{

	@Resource(name="UsersDao")
	private UsersDao usersDao;
	/**
	 * 登录账号密码校验
	 */
	@Override
	public UntilEntity<Users> queryLogin(Users user) {
		// TODO Auto-generated method stub
		Users u = usersDao.queryLogin(user);
		UntilEntity<Users> userEntity = new UntilEntity<Users>();
		String flag ;
		if(u != null){
				flag = "success";
				userEntity.setEntity(u);
		}else{
			flag = "errorpw";
		}
		userEntity.setRemark(flag);
		return userEntity;
	}
	
	
	@Override
	public String updateUser(UserOrder u) {
		// TODO Auto-generated method stub
		Users u1 = new Users();
		u1.setUserAccount(u.getUserAccount());
		u1.setPassword(u.getPassword());
		Users u2 = usersDao.queryLogin(u1);
		if(u2 != null){
			if(u.getNewPassword1().equals(u.getNewPassword2())){
				u2.setPassword(u.getNewPassword1());
				usersDao.updateUser(u2);
				return "succ";
			}else{
				return "fail2";
			}
		}
		return "fail1";
	}


	public UsersDao getUsersDao() {
		return usersDao;
	}
	public void setUsersDao(UsersDao usersDao) {
		this.usersDao = usersDao;
	}
	
	
	

	
}
